import { useState } from "react"
import apiV1 from "@/apis"
import { toast } from "react-toastify"
interface CreateAccountForm {
    channel_name: string
    account: string
    first_name?: string
    middle_name?: string
    last_name?: string
}

export default () => {
    const [loading, setLoading] = useState(false)
    const [success, setSuccess] = useState(false)

    const addAccount = async (params: CreateAccountForm) => {
        try {
            setLoading(true)
            const res = await apiV1.v1.refUpdateFinanceAccount(params)

            if (res.data.status) {
                toast.success("Account added successfully.")
                setSuccess(true)
            }
        } catch (error) {
            toast.error(error instanceof Error ? error.message : String(error))
            setSuccess(false)
        } finally {
            setLoading(false)
        }
    }

    return {
        addAccount,
        loading,
        success,
    }
}
